﻿using FangPage.Common;
using FangPage.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FangPage.User.Model
{
    public class Department
    {
        private string m_id = String.Empty;//部门ID
        private string m_parentid = String.Empty;//父部门ID
        private string m_parentname = String.Empty;//父名称
        private string m_name = String.Empty;//部门名称
        private string m_shortname = String.Empty;//部门简称
        private int m_depth;//部门层级
        private int m_display;//部门排序
        private short m_status = 1;//是否可用

        /// <summary>
        /// 部门ID
        /// </summary>
        [PrimaryKey]
        [UUID]
        public string id
        {
            get { return m_id; }
            set { m_id = value; }
        }

        /// <summary>
        /// 父部门ID
        /// </summary>
        [LeftJoin("Department",1,"id")]
        public string parentid
        {
            get { return m_parentid; }
            set { m_parentid = value; }
        }

        /// <summary>
        /// 父名称
        /// </summary>
        [Map("Department", 1, "name")]
        public string parentname
        {
            get
            {
                if (m_id.IsNullOrEmpty() && !m_parentid.IsNullOrEmpty())
                {
                    Department parentinfo = DbHelper.ExcuteModel<Department>(m_parentid);

                    m_parentname = parentinfo.name;
                }

                return m_parentname;
            }
            set { m_parentname = value; }
        }

        /// <summary>
        /// 部门名称
        /// </summary>
        public string name
        {
            get { return m_name; }
            set { m_name = value; }
        }

        /// <summary>
        /// 部门简称
        /// </summary>
        public string shortname
        {
            get { return m_shortname; }
            set { m_shortname = value; }
        }

        /// <summary>
        /// 部门层级
        /// </summary>
        public int depth
        {
            get { return m_depth; }
            set { m_depth = value; }
        }

        /// <summary>
        /// 部门排序
        /// </summary>
        public int display
        {
            get { return m_display; }
            set { m_display = value; }
        }

        /// <summary>
        /// 是否可用
        /// </summary>
        public short status
        {
            get { return m_status; }
            set { m_status = value; }
        }
    }
}
